package ucm;

import java.sql.Connection;
import java.sql.Statement;
import model.Database_Model;
import model.Line_Model;

public class UCRegisterLine {

    private String name, price, destination, time, gst;
    private Line_Model lm;

    public UCRegisterLine(view.Air_Manager man) {
        this.lm = man.getLineModel();

        this.name = lm.getName();
        this.price = lm.getPrice();
        this.destination = lm.getDestination();
        this.time = lm.getTime();
        this.gst = lm.getGst();
    }

    public String run() {
        boolean inserted = false;
        if (this.name.isEmpty()) {
            return "Please input line name in the list.";
        } else if (this.price.isEmpty()) {
            return "Please input line price in the list.";
        } else if (this.destination.isEmpty()) {
            return "Please input line destination in the list.";
        } else if (this.time.isEmpty()) {
            return "Please input line time in the list.";
        } else {

            try {
                Connection con = new Database_Model().getConnection();
                Statement stmt = con.createStatement();
                System.out.println("insert into airline value ('" + name + "','" + price + "','" + destination + "','"+ time
                        + "','" + gst + "')");
                stmt.executeUpdate("insert into airline value ('" + name + "','" + price + "','" + destination + "','"+ time
                        + "','" + gst + "')");
                return "Congratulate! ";
            } catch (Exception e) {
                return "Failed! ";
            }
        }
    }
}
